import json
import pandas as pd

# 读取JSON文件
with open('codelinter.json', 'r', encoding='utf-8') as file:
    data = json.load(file)

# 准备数据以便写入Excel
rows = []
for item in data:
    filePath = item['filePath']
    messages = item['messages']
    for message in messages:
        rule1 = message['rule'].replace("@","").replace("ArkTS-eslint","typescript-eslint").replace("-check","")
        row = {
            'ruleId': rule1,
            'filePath': item['filePath'][77:],
            'message': message['message'],
            'line': message['line'],
            'column': message['column'],
            'severity': message['severity']
        }
        rows.append(row)

# 创建DataFrame
df = pd.DataFrame(rows)

# 设置表头
df.columns = ['ruleId', 'filePath', 'message', 'line', 'column', 'severity']

# 写入Excel文件
df.to_excel('codelinter.xlsx', index=False)